package br.com.felix.easyfileexplorer;

import java.io.File;
import javax.swing.Icon;


/**
 * The class is just a helper class to display files in the UI.
 * */
public class EasyFile extends File{

	private static final long serialVersionUID = 249667681984412181L;
	
	
	/**
	 * It is not being used. But the idea was that if you started some operation, like CUT, you would
	 * signal it to display the file appearence in the UI.
	 * */
	private FileOperation operation = FileOperation.NONE;
	
	public EasyFile(File file) {
		super(file.getAbsolutePath());
	}

	
	/**
	 * Returns the file name. In case of root folders (that have no file name) returns the absolutePath.
	 * */
	@Override
	public String toString(){
		String name = getName();
		if(name.length()==0)name = getAbsolutePath();
		return name;
	}

	
	public FileOperation getOperation() {
		return operation;
	}

	
	public void setOperation(FileOperation operation) {
		this.operation = operation;
	}
	
	
	/**
	 * Returns a different icon for files and folders.
	 * */
	public Icon getIcon(){
		if(getName().length()==0){
			return EasyIcon.DRIVE.icon();
		}
		if(operation == FileOperation.NONE){
			return isDirectory()?EasyIcon.FOLDER.icon():EasyIcon.FILE.icon();
		}
		return operation.getIcon();
	}


}
